﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace SilverPOP.Library.Utilities
{
    public class MessageDisplayHelper
    {
        
        public static void ClearMessage(HtmlGenericControl divMessage)
        {
            divMessage.InnerHtml = "";
            divMessage.Style.Value = "display:none;";
        }
        
        public static void ShowMessage(HtmlGenericControl divMessage,object message,bool isError,bool isInfo)
       {
           divMessage.Visible = true;
           if (!isError)
           {
               divMessage.Style.Value = "display:block;";
               
               if(isInfo)
                  divMessage.Attributes.Add("class", "notice");
               else
                  divMessage.Attributes.Add("class", "success");
               
               divMessage.InnerHtml = message as string;
           }
           else
           {
               Exception ex = message as Exception;
               divMessage.Style.Value = "display:block;";
               divMessage.Attributes.Add("class", "error");
               if (ex != null)
                   divMessage.InnerHtml = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
               else
                   divMessage.InnerHtml = message as string;
           }
       }
        

       public static void ShowMessage(HtmlGenericControl divMessage, Literal ltlMessage, object message, bool isError, bool isInfo)
       {
           if (!isError)
           {
               divMessage.Style.Value = "display:block;";

               if (isInfo)
                   divMessage.Attributes.Add("class", "notice");
               else
                   divMessage.Attributes.Add("class", "success");

               ltlMessage.Text = message as string;
           }
           else
           {
               Exception ex = message as Exception;
               divMessage.Style.Value = "display:block;";
               divMessage.Attributes.Add("class", "error bsmsg-full");
               if (ex != null)
                   ltlMessage.Text = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
               else
                   ltlMessage.Text = message as string;
           }
       }

       public static void ShowMessage(HtmlGenericControl divMessage, object message, bool isError, bool isInfo, string extraClass)
       {
           divMessage.Style.Value = "display:block;";
           if (!isError)
           {
               if (isInfo)
                   divMessage.Attributes.Add("class", "notice " + extraClass);
               else
                   divMessage.Attributes.Add("class", "success " + extraClass);

               divMessage.InnerHtml = message as string;
           }
           else
           {
               Exception ex = message as Exception;
               divMessage.Visible = true;
               divMessage.Attributes.Add("class", "error " + extraClass);
               if (ex != null)
                   divMessage.InnerHtml = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
               else
                   divMessage.InnerHtml = message as string;
           }
       }
    
    }
}
